package com.nbsaas.boot.data.rest.convert;

import com.nbsaas.boot.data.data.entity.QueryTemplateHistory;
import com.nbsaas.boot.data.api.domain.request.QueryTemplateHistoryRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.data.data.entity.QueryTemplate;
            import com.nbsaas.boot.jpa.data.entity.User;

/**
* sql历史请求对象转换成实体对象
*/

public class QueryTemplateHistoryEntityConvert  implements Converter<QueryTemplateHistory, QueryTemplateHistoryRequest> {

    @Override
    public QueryTemplateHistory convert(QueryTemplateHistoryRequest source) {
        QueryTemplateHistory result = new QueryTemplateHistory();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getQueryTemplate()!=null){
                    QueryTemplate queryTemplate =new QueryTemplate();
                    queryTemplate.setId(source.getQueryTemplate());
                    result.setQueryTemplate(queryTemplate);
                    }
                    if(source.getCreator()!=null){
                    User creator =new User();
                    creator.setId(source.getCreator());
                    result.setCreator(creator);
                    }
        return result;
    }
}

